package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.FaultRepair;
import com.ruoyi.system.service.IFaultRepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备故障报修记录Controller
 *
 * @author ruoyi
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/system/repair")
public class FaultRepairController extends BaseController {
    @Autowired
    private IFaultRepairService faultRepairService;

    /**
     * 查询设备故障报修记录列表
     */
    //@PreAuthorize("@ss.hasPermi('system:repair:list')")
    @GetMapping("/list")
    public TableDataInfo list(FaultRepair faultRepair) {
        startPage();
        List<FaultRepair> list = faultRepairService.selectFaultRepairList(faultRepair);
        return getDataTable(list);
    }

    /**
     * 导出设备故障报修记录列表
     */
    //@PreAuthorize("@ss.hasPermi('system:repair:export')")
    //@Log(title= "设备故障报修记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FaultRepair faultRepair) {
        List<FaultRepair> list = faultRepairService.selectFaultRepairList(faultRepair);
        ExcelUtil<FaultRepair> util = new ExcelUtil<FaultRepair>(FaultRepair.class);
        util.exportExcel(response, list, "设备故障报修记录数据");
    }

    /**
     * 获取设备故障报修记录详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:repair:query')")
    @GetMapping(value = "/{repairCode}")
    public AjaxResult getInfo(@PathVariable("repairCode") String repairCode) {
        return success(faultRepairService.selectFaultRepairByRepairCode(repairCode));
    }

    /**
     * 新增设备故障报修记录
     */
    //@PreAuthorize("@ss.hasPermi('system:repair:add')")
    //@Log(title= "设备故障报修记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FaultRepair faultRepair) {
        return toAjax(faultRepairService.insertFaultRepair(faultRepair));
    }

    /**
     * 修改设备故障报修记录
     */
    //@PreAuthorize("@ss.hasPermi('system:repair:edit')")
    //@Log(title= "设备故障报修记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FaultRepair faultRepair) {
        return toAjax(faultRepairService.updateFaultRepair(faultRepair));
    }

    /**
     * 删除设备故障报修记录
     */
    //@PreAuthorize("@ss.hasPermi('system:repair:remove')")
    //@Log(title= "设备故障报修记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{repairCodes}")
    public AjaxResult remove(@PathVariable String[] repairCodes) {
        return toAjax(faultRepairService.deleteFaultRepairByRepairCodes(repairCodes));
    }
}
